<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for src/service.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="..\prettify.css" />
    <link rel="stylesheet" href="..\base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(..\sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="..\index.html">All files</a> / <a href="index.html">src</a> service.js
    </h1>
    <div class='clearfix'>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" >import axios from 'axios'</span>
&nbsp;
const service = <span class="cstat-no" title="statement not covered" >axios.create({</span>
    //baseURL会自动加在接口地址上
    baseURL: '/api',
    //指定请求超时的毫秒数,请求花费的时间超过设置时间则会被中断
    timeout: 3000,
    // `withCredentials` 表示跨域请求时是否需要使用凭证
    withCredentials: true,
    header: {
        "Content-type": "application/json;charset=utf-8"
    }
})
&nbsp;
// 添加请求拦截器
<span class="cstat-no" title="statement not covered" >service.interceptors.request.use(<span class="fstat-no" title="function not covered" >function (</span>config) {</span>
    // 在发送请求之前做些什么
    const token = <span class="cstat-no" title="statement not covered" >localStorage.getItem('token')</span>
<span class="cstat-no" title="statement not covered" >    if (token) {</span>
<span class="cstat-no" title="statement not covered" >        config.headers.token = token</span>
    }
<span class="cstat-no" title="statement not covered" >    return config;</span>
}, <span class="fstat-no" title="function not covered" >function (</span>error) {
    // 对请求错误做些什么
<span class="cstat-no" title="statement not covered" >    return Promise.reject(error);</span>
});
&nbsp;
// 添加响应拦截器
service.interceptors.response.use(<span class="fstat-no" title="function not covered" >function (</span>response) {
    // 对响应数据做点什么
<span class="cstat-no" title="statement not covered" >    return response.data;</span>
}, <span class="fstat-no" title="function not covered" >function (</span>error) {
    // 对响应错误做点什么
<span class="cstat-no" title="statement not covered" >    return Promise.reject(error);</span>
});
&nbsp;
export default service</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Wed Dec 14 2022 21:15:29 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="..\prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="..\sorter.js"></script>
</body>
</html>
